<?php

/**
 * Tanaxia_Router.php
 *
 * The Tanaxia_Router class that will guide us to the right controller based on the URI
 * 
 * Copyright 2009, Marcus Schumann - Tanax
 * Licensed under The MIT License - Modification, Redistribution allowed but must retain the above copyright notice
 * @link 		http://www.opensource.org/licenses/mit-license.php
 *
 * @package 	Tanaxia_Router - TAF
 * @created 	Mars 26th 2009
 * @version 	1.0
 * @link		-
 * 
 * @changelog
 * - 09/03/26	v1.0	Initial release
 */

class Tanaxia_Router
{
	
	/*
	|--------------------------------------------
	| $uri
	|--------------------------------------------
	|
	| An array of all the URI elements in the URL
	|
	*/
	private $uri = array();
	
	/*
	|--------------------------------------------------------------------------
	| initiate
	|--------------------------------------------------------------------------
	|
	| Assign the URI elements to an array, run route function
	|
	*/
	public function initiate($uri)
	{
		
		$this->uri = $uri;
		$this->route();
		
	}
	
	/*
	|--------------------------------------------------------------------------
	| router
	|--------------------------------------------------------------------------
	|
	| Routes us to the correct controller based on the array of URI segments
	|
	*/
	private function route()
	{
		
		$this->uri[] = '';
		
		if($this->uri[1] == '') // If the first URI segment is blank
		{
			
			$config = Tanaxia_Core::get('config');
			$default_controller = $config->default_controller;
			Tanaxia_Loader::controller($default_controller);
			
		}
		
		elseif($this->uri[2] == '')
		{
			
			Tanaxia_Loader::controller($this->uri[1]);
			
		}
		
		elseif($this->uri[3] == '')
		{
			
			Tanaxia_Loader::controller($this->uri[1], $this->uri[2]);
			
		}
		
		else
		{
			
			Tanaxia_Loader::controller($this->uri[1], $this->uri[2], $this->uri[3]);
			
		}
		
	}
	
}


// End of Tanaxia_Router.php